package Controller;

import Pojo.Student;
import Service.ServiceImpl.StudentServiceImpl;
import Service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by MI on 2021/7/7.
 */
@WebServlet("/findUserById")
public class FindUserById extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Integer id = Integer.valueOf(request.getParameter("id"));

        StudentService studentService = new StudentServiceImpl();
        Student student = new Student();
        student = studentService.findUserById(id);
        if(student!=null){
            request.setAttribute("student",student);
            request.getRequestDispatcher("/admin/update.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("/admin/user.jsp").forward(request,response);
        }
    }
}
